package com.yungu.swift.api.route.v1.common;


import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.system.sys.model.dto.SysCityDto;
import com.yungu.swift.system.sys.model.dto.SysProvinceDto;
import com.yungu.swift.system.sys.service.SysCityService;
import com.yungu.swift.system.sys.service.SysProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/province")
@Api(value = "【公共】省份信息接口", tags = "省份信息")
public class ProvinceApi extends BaseApi {

    @Reference
    private SysProvinceService sysProvinceService;

    @Reference
    private SysCityService sysCityService;

    @ApiOperation(value = "获取省份列表", notes = "省份列表")
    @RequestMapping(value = {"/list"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<List<SysProvinceDto>> list() {
        Map<String,Object> map = new HashMap();
        return sysProvinceService.list(map);
    }

    @ApiOperation(value = "根据省份id获取区县列表", notes = "省份列表")
    @RequestMapping(value = {"/city/list"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public ResponseData<List<SysCityDto>> cityList(
            @ApiParam(name = "provinceid", value = "省份表id", required = true) @RequestParam String provinceid
    ) {
        Map<String,Object> map = new HashMap();
        map.put("father",provinceid);
        return sysCityService.list(map);
    }
}
